package com.example.controller;

import com.example.mapper.DrugUserMapper;
import com.example.pojo.dto.DrugDTO;
import com.example.pojo.dto.DrugUserRegDTO;
import com.example.pojo.vo.DrugUserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DrugUserController {

    @Autowired(required = false)
    DrugUserMapper mapper;
    @RequestMapping("/login")
    public int login(@RequestBody DrugDTO drugUser){
        System.out.println(drugUser);
        DrugUserVO u = mapper.selectByUsername(drugUser.getUsername());
        if (u!=null){
            if (u.getPassword().equals(drugUser.getPassword())){
                return 1;
            }
            return 3;
        }
        return 2;
    }

    @RequestMapping("/reg")
    public int reg(@RequestBody DrugUserRegDTO drugUserReg){
        DrugUserVO u = mapper.selectByUsername(drugUserReg.getUsername());
        if (u!=null){
            return 2;
        }else {
            mapper.insertDurgUser(drugUserReg);
            return 1;
        }
    }


}
